package com.gkzf.ai.module.crm.service.creditreportsimple.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkzf.ai.framework.common.pojo.PageResult;
import com.gkzf.ai.framework.common.util.object.BeanUtils;
import com.gkzf.ai.framework.security.core.util.SecurityFrameworkUtils;
import com.gkzf.ai.module.crm.controller.admin.simpleCredit.vo.CreditReportSimplePageReqVO;
import com.gkzf.ai.module.crm.controller.admin.simpleCredit.vo.CreditReportSimpleRespVO;
import com.gkzf.ai.module.crm.controller.admin.simpleCredit.vo.CreditReportSimpleSaveReqVO;
import com.gkzf.ai.module.crm.dal.dataobject.creditreportsimple.CreditReportSimpleDO;
import com.gkzf.ai.module.crm.dal.mysql.creditreportsimple.CreditReportSimpleMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * CRM 征信报告简版 Service 实现类
 *
 * @author 国科智飞
 */
@Slf4j
@Service
public class CreditReportSimpleServiceImpl implements CreditReportSimpleService {

    @Resource
    private CreditReportSimpleMapper creditReportSimpleMapper;

    @Override
    public CreditReportSimpleRespVO getCreditReportSimple(Long id) {
        CreditReportSimpleDO creditReportSimpleDO = creditReportSimpleMapper.selectById(id);
        return BeanUtils.toBean(creditReportSimpleDO, CreditReportSimpleRespVO.class);
    }


    @Override
    public void allocation(CreditReportSimpleSaveReqVO createReqVO) {
        CreditReportSimpleDO simpleDO = creditReportSimpleMapper.selectById(createReqVO.getId());
        simpleDO.setUserId(createReqVO.getUserId());
        creditReportSimpleMapper.updateById(simpleDO);
    }

    @Override
    public PageResult<CreditReportSimpleRespVO> getCreditReportSimplePage(CreditReportSimplePageReqVO pageReqVO) {
        pageReqVO.setUserId(SecurityFrameworkUtils.getLoginUserId());
        pageReqVO.setDeptId(SecurityFrameworkUtils.getLoginUserDeptId());
        IPage<CreditReportSimpleRespVO> respPage = creditReportSimpleMapper.selectPage(new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO);
        return new PageResult<>(respPage.getRecords(), respPage.getTotal());
    }


}